# Auto Reload Extension
class window.Develop
  latestVersion = null
  TIME = 500

  checkReloadExtension = =>
    $.post(getLocalServerUrl(), JSON.stringify(method: 'get_latest_version')).success (response) =>
      if latestVersion isnt null and latestVersion isnt response
        @reloadExtension()

      if latestVersion is null
        chrome.tabs.reload bypassCache: true

      latestVersion = response

  @init: ->
    setInterval checkReloadExtension, TIME if Option.get 'debug'

  @reloadExtension = ->
    chrome.tabs.query url: 'chrome://extensions-frame/', currentWindow: true, (tabs) ->
      if tabs.length > 0
        chrome.tabs.reload tabs[0].id, bypassCache: true
      else
        chrome.tabs.create url: 'chrome://extensions-frame/', active: false, pinned: true
